package top.leyi.handle;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import top.leyi.IService.ICollectionService;
import top.leyi.entity.pushAndColle.Collection0;
import top.leyi.entity.user.User;
import top.leyi.utils.Result;
import top.leyi.utils.ResultGenerator;

/**
 * @desc 收藏消息
 */

@RestController
@RequestMapping("/api/collect")
public class CollectionHandle {

    @Autowired
    ICollectionService collectionService;
    @GetMapping("/{page}")
    public Result doGet(@RequestParam("id") int userId,
                        @RequestParam("token") String token,
                        @PathVariable("page") int page) {
        User user = new User();
        user.setId(userId);
        return new Result(200, collectionService.getAllCollection(user, page));
    }

    @DeleteMapping("")
    public Result doDelete(@RequestParam("collectionId") int collectionId,
                           @RequestParam("token") String token,
                           @RequestParam("id") int userId){
        Collection0 collection0 = new Collection0();
        collection0.setId(collectionId);

        User user = new User();
        user.setToken(token);
        user.setId(userId);
        collectionService.removeCollection(collection0, user);
        return ResultGenerator.OK.getResult();
    }

     /**
     * @desc 添加收藏,收藏的是说说id
     */
    @PostMapping("")
    public Result doPost(@RequestParam("token") String token,
                         @RequestParam("talkId") int original,
                         @RequestParam("id") int userId
                          ){
        Collection0 collection0 = new Collection0();
        collection0.setOriginal(original);
        collection0.setDest(userId);
        collection0.setType("说说");

        User user = new User();
        user.setToken(token);
        user.setId(userId);

        collectionService.addOneCollection(collection0, user);
        return ResultGenerator.OK.getResult();
    }
}
